home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.Stanford.EDU!microunity!toms
- From: toms@MicroUnity.com (Tom Sanders)
- Subject: Re: while loop problem
- Message-ID: <Do6DB0.EtE@microunity.com>
- Sender: usenet@microunity.com (news id)
- Organization: MicroUnity Systems Engineering, Inc.
- References: <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca>
- Date: Tue, 12 Mar 1996 22:04:12 GMT
-
- In article <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca>, Bill Simpson <wsimpson@uwinnipeg.ca> writes:
- |> Consider the following code fragment:
- |>
- |> y=2000; z=1000;
- |> x=0;
- |> while(x<=XMAX)
- |> {
- |> x+=(int) erand(mean);
- |> setdot(x,y,z);
- |> }
- |>
- |> It plots a line of dots that are randomly (exponentially) spaced, giving
- |> a 1D spatial Poisson process.
- |> The problem is that dot x coordinates can only be between 0 and XMAX.
- |> The above code will also attempt to plot one point at an x value >XMAX
- |> before it terminates.
- |>
- |> Is there a nice way to write the code so it works properly?
- |>
- |> The only way I have thought of is
- |> y=2000; z=1000;
- |> x=0;
- |> while(x<=XMAX)
- |> {
- |> x+=(int) erand(mean);
- |> if(x<=XMAX)
- |> setdot(x,y,z);
- |> }
- |>
- |> which seems very clumsy since the same test is done twice.
- |>
- |> Thanks very much for any help.
- |>
- |> Bill Simpson
-
- How about:
-
- y=2000; z=1000;
- x=0;
- do {
- x+=(int) erand(mean);
- setdot(x,y,z);
- } while(x<=XMAX)
-
- Tom Sanders
-